User pages

jamesperet 11 years ago
parent
commit
172b94fc42

+ 4 - 0
app/controllers/agent_controller.rb

@@ -1,10 +1,14 @@
1 1
 class AgentController < ApplicationController
2
+  
2 3
   def current_missions
4
+    
3 5
   end
4 6
 
5 7
   def choose_mission
8
+    
6 9
   end
7 10
 
8 11
   def agent_profile
12
+      @user = User.find(params[:id])
9 13
   end
10 14
 end

+ 4 - 6
app/controllers/application_controller.rb

@@ -3,12 +3,10 @@ class ApplicationController < ActionController::Base
3 3
   # For APIs, you may want to use :null_session instead.
4 4
   protect_from_forgery with: :exception
5 5
   
6
-  config.to_prepare do
7
-      Devise::SessionsController.layout "auth"
8
-      Devise::RegistrationsController.layout "auth"
9
-      Devise::ConfirmationsController.layout "auth"
10
-      Devise::UnlocksController.layout "auth"
11
-      Devise::PasswordsController.layout "auth"
6
+  before_filter :configure_permitted_parameters, if: :devise_controller?
7
+
8
+  def configure_permitted_parameters
9
+    devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:username, :location, :current_password) }
12 10
   end
13 11
   
14 12
 end

+ 5 - 1
app/controllers/missions_controller.rb

@@ -1,5 +1,9 @@
1 1
 class MissionsController < ApplicationController
2 2
   before_action :set_mission, only: [:show, :edit, :update, :destroy]
3
+  
4
+  before_action :authenticate_user!
5
+  
6
+  layout 'front_end'
3 7
 
4 8
   # GET /missions
5 9
   # GET /missions.json
@@ -69,6 +73,6 @@ class MissionsController < ApplicationController
69 73
 
70 74
     # Never trust parameters from the scary internet, only allow the white list through.
71 75
     def mission_params
72
-      params.require(:mission).permit(:title, :description, :status, :agent_search_start, :agent_search_end)
76
+      params.require(:mission).permit(:title, :description, :status, :agent_search_start, :agent_search_end, :mission_agent_attributes)
73 77
     end
74 78
 end

+ 8 - 1
app/controllers/users/registrations_controller.rb

@@ -1,7 +1,7 @@
1 1
 class users::registrationsController < Devise::registrationsController
2 2
   
3 3
   layout 'auth'
4
-  
4
+
5 5
   # def new
6 6
   #   super
7 7
   # end
@@ -9,4 +9,11 @@ class users::registrationsController < Devise::registrationsController
9 9
   # def create
10 10
   #   super
11 11
   # end
12
+  
13
+  protected
14
+
15
+    def after_update_path_for(resource)
16
+      user_path(resource)
17
+    end
18
+    
12 19
 end

+ 2 - 0
app/models/mission.rb

@@ -1,2 +1,4 @@
1 1
 class Mission < ActiveRecord::Base
2
+  has_many :mission_agents
3
+  accepts_nested_attributes_for :mission_agents, allow_destroy:true
2 4
 end

+ 3 - 0
app/models/mission_agent.rb

@@ -1,4 +1,7 @@
1 1
 class MissionAgent < ActiveRecord::Base
2 2
   belongs_to :mission
3 3
   belongs_to :user
4
+  
5
+  has_many :mission_agent_steps
6
+  accepts_nested_attributes_for :mission_agent_steps, allow_destroy:true
4 7
 end

+ 1 - 2
app/views/agent/agent_profile.html.erb

@@ -1,2 +1 @@
1
-<h1>Agent#agent_profile</h1>
2
-<p>Find me in app/views/agent/agent_profile.html.erb</p>
1
+<h1><%= @user.email %></h1>

+ 2 - 1
app/views/devise/registrations/edit.html.erb

@@ -4,7 +4,8 @@
4 4
   <%= f.error_notification %>
5 5
 
6 6
   <div class="form-inputs">
7
-    <%= f.input :email, required: true, autofocus: true %>
7
+    <%= f.input :username, required:true, autofocus: true %>
8
+    <%= f.input :email, required: true %>
8 9
 
9 10
     <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
10 11
       <p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>

+ 2 - 1
app/views/devise/registrations/new.html.erb

@@ -4,7 +4,8 @@
4 4
   <%= f.error_notification %>
5 5
 
6 6
   <div class="form-inputs">
7
-    <%= f.input :email, required: true, autofocus: true %>
7
+    <%= f.input :username, required:true, autofocus: true %>
8
+    <%= f.input :email, required: true %>
8 9
     <%= f.input :password, required: true %>
9 10
     <%= f.input :password_confirmation, required: true %>
10 11
   </div>

+ 2 - 12
app/views/layouts/application.html.erb

@@ -55,19 +55,9 @@
55 55
       </div>
56 56
     </div>
57 57
 
58
-    <div class="container-fluid">
58
+    <div class="container-fluid" style="margin-left: 18px; margin-right: 18px;">
59 59
       <div class="row-fluid">
60
-        <div class="span3">
61
-          <div class="well sidebar-nav">
62
-            <ul class="nav nav-list">
63
-              <li class="nav-header">Sidebar</li>
64
-              <li><%= link_to "Link1", "/path1"  %></li>
65
-              <li><%= link_to "Link2", "/path2"  %></li>
66
-              <li><%= link_to "Link3", "/path3"  %></li>
67
-            </ul>
68
-          </div><!--/.well -->
69
-        </div><!--/span-->
70
-        <div class="span9">
60
+        <div class="span12">
71 61
           <%= bootstrap_flash %>
72 62
           <%= yield %>
73 63
         </div>

+ 1 - 12
app/views/layouts/front_end.html.erb

@@ -56,21 +56,10 @@
56 56
 
57 57
     <div class="container top-container">
58 58
         <div class="row">
59
-          <div class="span9">
59
+          <div class="span12">
60 60
             <%= bootstrap_flash %>
61 61
             <%= yield %>
62 62
           </div>
63
-          <div class="span3">
64
-            <div class="well sidebar-nav">
65
-              <h3>Sidebar</h3>
66
-              <ul class="nav nav-list">
67
-                <li class="nav-header">Sidebar</li>
68
-                <li><%= link_to "Link1", "/path1"  %></li>
69
-                <li><%= link_to "Link2", "/path2"  %></li>
70
-                <li><%= link_to "Link3", "/path3"  %></li>
71
-              </ul>
72
-            </div><!--/.well -->
73
-          </div><!--/span-->
74 63
         </div><!--/row-->
75 64
 
76 65
       <footer>

+ 27 - 3
app/views/layouts/partials/_nav_links.html.erb

@@ -1,5 +1,29 @@
1 1
 <ul class="nav">
2
-   <li><%= link_to "About", start_about_path  %></li>
3
-   <li><%= link_to "Login", new_user_session_path  %></li>
4
-   <li><%= link_to "Sign Up", new_user_registration_path  %></li>
2
+   <% if user_signed_in? %>
3
+   	<li><%= link_to "Missions", missions_path  %></li>
4
+   <% else %>
5
+   	<li><%= link_to "About", start_about_path  %></li>
6
+   	
7
+   <% end %>
8
+</ul>
9
+
10
+<ul class="nav pull-right">
11
+	<% if user_signed_in? %>
12
+		<li class="dropdown">
13
+			<a href="#" class="dropdown-toggle" data-toggle="dropdown">
14
+				<% if current_user.username %>
15
+					<%= current_user.username %> <b class="caret"></b>
16
+				<% else %>
17
+					<%= current_user.email %> <b class="caret"></b>
18
+				<% end %>
19
+			</a>
20
+		    	<ul class="dropdown-menu">
21
+	  			<li><%= link_to 'Edit profile', edit_user_registration_path %></li>
22
+	  			<li><%= link_to "Logout", destroy_user_session_path, method: :delete %></li>
23
+			</ul>
24
+		</li>
25
+	<% else %>
26
+		<li><%= link_to "Login", new_user_session_path  %></li>
27
+		<li><%= link_to "Sign Up", new_user_registration_path  %></li>
28
+	<% end %>
5 29
 </ul>

+ 6 - 1
app/views/missions/_form.html.erb

@@ -1,12 +1,17 @@
1 1
 <%= simple_form_for(@mission) do |f| %>
2 2
   <%= f.error_notification %>
3
-
4 3
   <div class="form-inputs">
5 4
     <%= f.input :title %>
6 5
     <%= f.input :description %>
7 6
     <%= f.input :status %>
8 7
     <%= f.input :agent_search_start %>
9 8
     <%= f.input :agent_search_end %>
9
+    
10
+    <% @agent = 1 %>
11
+    <%= f.fields_for :mission_agents, MissionAgent.order('created_at ASC').find_all_by_mission_id(@mission) do |builder| %>
12
+    		<%= render 'mission_agent_form', f: builder %>
13
+    <%end%>
14
+    
10 15
   </div>
11 16
 
12 17
   <div class="form-actions">

+ 12 - 0
app/views/missions/_mission_agent_form.html.erb

@@ -0,0 +1,12 @@
1
+<fieldset class="well">
2
+	<h3>Agent <%= @agent %></h3>
3
+	<% @step  = 1 %>
4
+	<%= f.label :description, "Description"%><br/>
5
+	<%= f.text_area :description%><br/>
6
+	<%= f.check_box :_destroy%>
7
+	<%= f.label :_destroy, "Remove Agent"%>
8
+	<%= f.fields_for :mission_agent_steps do |builder| %>
9
+		<%= render 'mission_agent_step_form', f: builder %>
10
+	<%end%>
11
+	<% @agent = @agent + 1 %>
12
+</fieldset>

+ 8 - 0
app/views/missions/_mission_agent_step_form.html.erb

@@ -0,0 +1,8 @@
1
+<fieldset>
2
+	<h4>Step <%= @step %></h4>
3
+	<%= f.label :description, "Description"%>
4
+	<%= f.text_field :description %>
5
+	<%= f.hidden_field :_destroy %>
6
+	<%= f.label :_destroy, "Remove Step"%>
7
+	<% @step = @step + 1 %>
8
+</fieldset>

+ 1 - 1
app/views/missions/index.html.erb

@@ -1,6 +1,6 @@
1 1
 <h1>Listing missions</h1>
2 2
 
3
-<table>
3
+<table class="table table-bordered">
4 4
   <thead>
5 5
     <tr>
6 6
       <th>Title</th>

+ 22 - 2
config/routes.rb

@@ -2,17 +2,37 @@ AvalancheGame::Application.routes.draw do
2 2
   get "start/about"
3 3
   get "agent/current_missions"
4 4
   get "agent/choose_mission"
5
-  get "agent/agent_profile"
5
+  get "agent/:id" => "agent#agent_profile"
6 6
   resources :missions
7 7
 
8
-  devise_for :users, :skip => [:sessions, :registrations]
8
+  
9
+  devise_for :users, :skip => [:sessions, :passwords, :confirmations, :registrations]
9 10
     as :user do
10 11
       get 'login' => 'devise/sessions#new', :as => :new_user_session
11 12
       post 'login' => 'devise/sessions#create', :as => :user_session
12 13
       delete 'logout' => 'devise/sessions#destroy', :as => :destroy_user_session
13 14
       get   'signup' => 'devise/registrations#new',    :as => :new_user_registration
14 15
       post  'signup' => 'devise/registrations#create', :as => :user_registration
16
+      put  'signup' => 'devise/registrations#update', :as => :user_registration_update
17
+      scope '/account' do
18
+          # password reset
19
+          get   '/reset-password'        => 'devise/passwords#new',    as: 'new_user_password'
20
+          put   '/reset-password'        => 'devise/passwords#update', as: 'user_password'
21
+          post  '/reset-password'        => 'devise/passwords#create'
22
+          get   '/reset-password/change' => 'devise/passwords#edit',   as: 'edit_user_password'
23
+          # confirmation
24
+          get   '/confirm'        => 'devise/confirmations#show',   as: 'user_confirmation'
25
+          post  '/confirm'        => 'devise/confirmations#create'
26
+          get   '/confirm/resend' => 'devise/confirmations#new',    as: 'new_user_confirmation'
27
+          # settings & cancellation
28
+          get '/cancel'   => 'devise/registrations#cancel', as: 'cancel_user_registration'
29
+          get '/settings' => 'devise/registrations#edit',   as: 'edit_user_registration'
30
+          put '/settings' => 'devise/registrations#update'
31
+          # account deletion
32
+          delete '' => 'devise/registrations#destroy'
33
+      end
15 34
     end
35
+    
16 36
   # The priority is based upon order of creation: first created -> highest priority.
17 37
   # See how all your routes lay out with "rake routes".
18 38